package coml.jiyun.hp.ershi;

import android.os.Bundle;
import com.google.android.material.tabs.TabLayout;
import java.util.ArrayList;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;
import coml.jiyun.hp.ershi.adapter.TabAdapter;
import coml.jiyun.hp.ershi.fragment.CollectFragment;
import coml.jiyun.hp.ershi.fragment.HomeFragment;

public class MainActivity extends AppCompatActivity {

    private TabLayout mMainTab;
    private ArrayList<String> list;
    private ArrayList<Fragment> fragments;
    private TabAdapter tabAdapter;
    private ViewPager mMainVp;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
    }

    private void initView() {
        mMainTab = (TabLayout) findViewById(R.id.main_Tab);
        mMainVp = (ViewPager) findViewById(R.id.main_vp);

        fragments = new ArrayList<>();
        fragments.add(new HomeFragment());
        fragments.add(new CollectFragment());

        list = new ArrayList<>();
        list.add("首页");
        list.add("收藏");

        TabAdapter tabAdapter = new TabAdapter(getSupportFragmentManager(), list, fragments);
        mMainVp.setAdapter(tabAdapter);
        mMainTab.setupWithViewPager(mMainVp);
    }
}
